<!--头部公共部分-->
{include file="common/header" /}
<div style="padding:15px;">
    <form class="layui-form layui-form-pane">
        <div class="layui-form-item">
            <label class="layui-form-label">上级菜单</label>
            <div class="layui-input-block">
                <select id="pid" name="pid" lay-verify="" lay-search>
                    <option value="0">一级菜单</option>
                    {foreach $list as $v}
                    <option value="{$v['id']}" {if condition="$menu['pid'] == $v['id']"}selected{/if} >{:str_repeat("┝",$v['level'])}{$v['title']}</option>
                    {/foreach}
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">菜单名称</label>
            <div class="layui-input-block">
                <input type="text" name="menuname" value="{$menu.title}" required lay-verify="required"  placeholder="请输入菜单名称，菜单名称与对应模块名称一致" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">控制器名称</label>
            <div class="layui-input-block">
                <input type="text" name="controller" value="{$opt[0]}" required lay-verify="required" placeholder="请输入控制器名称，一级菜单控制器为 * " autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">方法名称</label>
            <div class="layui-input-block">
                <input type="text" name="action" value="{$opt[1]}" required lay-verify="required" placeholder="请输入方法名称，一级菜单方法为 * " autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">菜单图标</label>
            <div class="layui-input-block">
                <input type="text" name="menuicon" value="{$menu.icon}" placeholder="请输入菜单图标" autocomplete="off" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux" style="margin-left: 120px;">
                <a href="http://www.layui.com/doc/element/icon.html" target="_blank" style="color: red;">具体点击参考layui官网</a>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">描述</label>
            <div class="layui-input-block">
                <textarea class="layui-textarea" name="condition" placeholder="请输入内容">{$menu.condition}</textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <input type="hidden" name="id" value="{$menu.id}">
                <input class="layui-btn" lay-submit lay-filter="form" value="立即提交" readonly>
            </div>
        </div>
    </form>
</div>
<!--底部公共部分-->
{include file="common/footer" /}

<script>
    layui.use(['element','jquery','form','layer'], function(){
        var $ = layui.jquery
                ,element = layui.element
                ,layer = layui.layer
                ,form = layui.form;
//监听提交
        form.on('submit(form)', function (data) {
            var field = data.field;
            var isLoad;
            $.ajax({
                url: '/admin/auth/menu_edit',
                method: "post",
                data: field,
                beforeSend: function () {
                    isLoad = layer.load(0, {
                        shade: false
                    }); //0代表加载的风格，支持0-2
                },
                success: function (result) {
                    layer.msg(result.msg);
                    if (result.code === 0) {
                        setTimeout(function () {
                            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.layer.close(index); //再执行关闭
                            parent.location.reload();
                        }, 2000);
                    }
                },
                complete: function () {
                    layer.close(isLoad)
                },
                error: function (error) {
                    console.log(error)
                }
            });
            return false;
        });

    });

</script>